﻿<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<LINK rel="Bookmark" href="../images/favicon.ico">
<!-- 本框架基本脚本和样式 -->
<script type="text/javascript"
	src="${path }/resource/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript"
	src="${path }/resource/js/systools/MBase.js"></script>

<title></title>
</head>
<body>
<div class="ibox-content">
	<form class="form-horizontal" id="dataform"
		onsubmit="javascripr:return false;">

		<input type="hidden" name="tokenUrl" value="${tokenUrl}"> 
		<input type="hidden" name="token" value="${token}">

		<c:if test="${obj ne null }">
			<input type="hidden" name="biId" value='<c:out value="${obj.biId}"></c:out>'>
		</c:if>
		
		<div class="form-group">
			<label class="col-sm-2 control-label">班级<span class="red">*</span></label>
			<div class="col-sm-4">
				<select name="stuClass" id="stuClass" class="form-control autoFull select2"
					data-url="${path}/admin/tabClass/showAllClass"
					data-def="${obj.stuClass }" onchange="changeStudent()" 
					data-filed="claName" data-value="claId"
					datatype="*" nullmsg="班级不能为空">
					<option value="">--请选择所在班级--</option>
				</select> 
				<div class="Validform_checktip"></div>
			</div>
			
			<label class="col-sm-2 control-label">学生<span class="red">*</span></label>
			<div class="col-sm-4">
				<select name="sId" id="stu" class="form-control autoFull select2 autoFull2"
					data-url="${path}/admin/studentinfo/showAllStudent"
					data-def="${obj.sId }"
					data-filed="stuName" data-value="stuId"
					datatype="*" nullmsg="学生不能为空">
					<option value="">--请选择学生--</option>
				</select>
				<div class="Validform_checktip"></div>
			</div>
			
		</div>

		<div class="form-group">			
			<label class="col-sm-2 control-label">奖金名目 <span class="red">*</span></label>
			<div class="col-sm-4">
				<select name="biItems" id="biItems" class="form-control autoFull select2"
					data-url="${path}/admin/bonusinfo/showBonusList"
					data-def="${obj.biItems }" 
					data-filed="bName" data-value="bName" 
					datatype="*" nullmsg="奖金名目不能为空">
					<option value="">--请选择奖金名目--</option>
				</select>
				<div class="Validform_checktip"></div> 			
			</div>		
				
			<label class="col-sm-2 control-label">奖金总金额 <span class="red">*</span></label>
			<div class="col-sm-4">
					<input type="text"	id="biMoney"  class="form-control" 
					value='<c:out value="${obj.biMoney}"></c:out>' 
					name="biMoney" nullmsg="金额不能为空">
				<div class="Validform_checktip"></div>	 
			</div>					
		</div>
		
		<div class="form-group">
			<label class="col-sm-2 control-label">备注</label>
			<div class="col-sm-4">
				<textarea rows="6" cols="" class="form-control" name="biRemark" 
				 datatype="*0-20">${obj.biRemark }</textarea>			
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-2 control-label"> 领款明细<span class="text-danger">*</span></label>
			<div class="col-sm-4">
			<button class="btn btn-success btn-sm" onclick="addInfo()" type="button">添加明细</button>
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-2 control-label"></label>
			<div class="col-sm-10 col-md-offset-2">
				<table class="table table-hover table-striped table-bordered"
				id="mgrid">
					<thead>
						<tr>
							<th>序号<span class="text-danger"></span></th>
							<th>领款人<span class="text-danger">*</span></th>
							<th>领款金额<span class="text-danger">*</span></th>
							<th>领款日期<span class="text-danger">*</span></th>
							<th>操作<span class="text-danger"></span></th>
						</tr>
					</thead>
					<tbody id="cpId">
						<c:if test="${obj eq null }">
							<tr>
								<td>1</td>
								<td><input class="form-control" errormsg="请填写1到16位字符" dataType="*1-16" name="bdList[0].bdPayee" ></td>
								<td><input class="form-control" errormsg="请填写1到30位字符" dataType="*1-30" name="bdList[0].bdMoney"  ></td>
								<td><input  class="form-control datetimepicker"  dataType="*" name="bdList[0].bdDate" ></td>
								 <td class="center"><a 
									class="fa fa-trash" onClick="delSelectItem(this)"
									href="javascript:;" title="删除"></a></td> 
							</tr>
						</c:if>
						<c:if test="${obj ne null }">
							<c:forEach var="item" items="${obj.bdList }" varStatus="count">
								<tr>
									<td>${count.index+1 }</td>
									<td><input type="hidden" value="${item.bdId }"  name="bdList[${count.index}].bdId">
									<input class="form-control" errormsg="请填写1到16位字符" dataType="*1-16" name="bdList[${count.index}].bdPayee" value="${item.bdPayee }" ><div class="Validform_checktip"></div></td>
									<td><input class="form-control" dataType="*" value="${item.bdMoney }"	name="bdList[${count.index}].bdMoney"><div class="Validform_checktip"></div></td>
									<td><input class="form-control  datetimepicker" 
											style=" display: inline;" 
					 						dataType="*" name="bdList[${count.index}].bdDate" value='<fmt:formatDate value="${item.bdDate }" pattern="yyyy-MM-dd"/>'><div class="Validform_checktip"></div></td>
									 <td class="center"><a class="fa fa-trash"
										onClick="delSelectItem(this)" href="javascript:;" title="删除"></a></td> 
								</tr>
							</c:forEach>
						</c:if>
					</tbody>
				</table>
			</div>
		</div>
			
		<div class="form-group ">
			<div class="col-sm-12 text-center">
				<a href="javascript:;" onclick="myForm.submit()" class="btn btn-success radius">保存</a>&nbsp;&nbsp;&nbsp;&nbsp;
				<button onclick="MTools.closeForm()" class="btn btn-danger radius" type="button">取消</button>
			</div>
		</div>
	</form>
</div>
</body>
<script type="text/javascript">
	<c:if test="${obj eq null }" >
	var count=0;
	</c:if>
	<c:if test="${obj ne null }" >
	var count=parseInt("${fn:length(obj.bdList)}");
	</c:if>
	
	
	var myForm;
	$(function(){
		//带搜索的下拉框
		$(".select2").select2({'width':'100%'});
		$(".select2").trigger("blur");
		//初始化下拉框
		MTools.autoFullSelect();
		//初始化日期控件
		MTools.ininDatetimepicker({
			listenBlur : true
		});
		
		//表格提交
		myForm = MForm.initForm({
			invokeUrl : "${path}/admin/bonusinfo/addOrModify",
			afterSubmit : function() {
				parent.myGrid.serchData();
			},
		});
		
	});
	
	<c:if test="${obj.stuClass ne null }">
	changeStudent()
	</c:if>
	
	function changeStudent() {
		var stuClass = $("#stuClass").val();
		<c:if test="${obj.stuClass ne null }">
		stuClass = "${obj.stuClass}";
		</c:if>
		if (stuClass != '') {
			$("#stu").removeData("url");
			$("#stu").data("url", "${path}/admin/paymentinfo/queryStuByClass?stuClass=" + stuClass);
			$("#stu").data("filed", "stuName");
			$("#stu").data("value", "stuId");
			<c:if test="${obj ne null }">
				$("#stu").data("def", "${obj.sId }");
			</c:if>
			$("#stu").empty();
			$("#stu").append('<option value="">-- 请选择指派人--</option>');
			MTools.autoFullSelect({
				selecteder : ".autoFull2"
			});
			$(".select2").select2({
				'width' : '100%'
			})
		} 
	}
	
	/* function changeMoney(){
		 var biOption1 = $("#biOption1").val();
		// console.log(biOption1); 
		// encodeURI(encodeURI(biOption1))
		if(biOption1 !=''){
		 $.ajax({
			type:"post",
			url :"${path}/admin/bonusinfo/changeMoney",
			data:{"bName":biOption1},
		    contentType:"application/x-www-form-urlencoded;charset=UTF-8",
			success : function(result) {
				for(var i = 0;i<result.rows.length;i++){
					$("#biMoney").attr("filed", "bNumber1");
					$("#biMoney").attr("value",result.rows[i].bNumber1);
					$("#biMoney").attr("def", "${obj.biMoney }");
					
				}
			}
		}); 
		}
	} */
	
	$('.select2').change(function() {
		if(this.value != "") {
			$(this).parent().children('.Validform_checktip').text('');
			$(this).parent().children('.Validform_checktip').removeClass('Validform_wrong');
			$(this).parent().children('.Validform_checktip').addClass('Validform_right');
		}
	});
	
	/**
	初始化明细列表
	*/
	function initGoodsTypes() {
		$.AjaxProxy({
			a : false,
			c : false
		}).invoke("${path}/admin/bonusDetail/showList",function(loj){
			$("#biId").createSelectTree(loj.attr("result").rows,{
			});
		});
	}
	
	//删除选中的元素
	function delSelectItem(node) {
		console.log("----");
		//移除tr
		$(node).closest('tr').remove();
		$("tbody").find("tr").each(function(i) {
			$(this).find("td").eq(0).html(i + 1);
		});
	}
	
	function addInfo(){
		
		var index=++count;
		var tIndex=$("tbody").find("tr").length;
		$("tbody").append(
				'<tr>'+
				'<td>'+(++tIndex)+'</td>'+
				'<td><input dataType="*" class="form-control" name="bdList['+index+'].bdPayee"  ><div class="Validform_checktip"></div> </td>'+
				'<td><input dataType="*" class="form-control" name="bdList['+index+'].bdMoney"  ><div class="Validform_checktip"></div> </td>'+
				'<td><input class="form-control  datetimepicker" style=" display: inline;"  dataType="*" name="bdList['+index+'].bdDate" ><div class="Validform_checktip"></div></td>'+
				 '<td class="center"><a  class="fa fa-trash" onClick="delSelectItem(this)" href="javascript:;" title="删除"></a></td>'+ 
				'</tr>'
				);
		
		//初始化日期控件
		MTools.ininDatetimepicker({
			listenBlur : true
		});
		
	}
	
</script>
</body>
</html>